﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Waiter.Common;

namespace Waiter.Controler
{
    class OtherRevenueCtrl
    {
        public List<OTHER_REVENUE> fsGetOtherRevenueList(DateTime dateFrom, DateTime dateTo)
        {
            try
            {
                List<OTHER_REVENUE> resultList = (from s in CommonGlobalVariable.globalDataContext.OTHER_REVENUEs
                                                  where s.DEL_FLG == CommonConstants.FLAG_OFF && s.UPD_DATE >= dateFrom && s.UPD_DATE <= dateTo
                                                  select s).ToList<OTHER_REVENUE>();
                return resultList;
            }
            catch (Exception ex)
            {
                CommonLogging.fsWriteLog(CommonConstants.LOG_TYPE_ERROR,
                    "OtherRevenueCtrl.fsGetOtherRevenueList",
                    CommonUtils.fsParamListToString(new object[2] { dateFrom, dateTo }),
                    ex.ToString());
                return null;
            }
        }

        public ResultStatus fsInsertNewItem(OTHER_REVENUE item)
        {
            try
            {
                CommonGlobalVariable.globalDataContext.OTHER_REVENUEs.InsertOnSubmit(item);
                CommonGlobalVariable.globalDataContext.SubmitChanges();
            }
            catch (Exception ex)
            {
                CommonLogging.fsWriteLog(CommonConstants.LOG_TYPE_ERROR,
                    "OtherRevenueCtrl.fsInsertNewItem",
                    CommonUtils.fsParamListToString(new object[1] { item }),
                    ex.ToString());
                return ResultStatus.ERROR;
            }
            return ResultStatus.SUCCESS;
        }

        public ResultStatus fsUpdateItem(string code, int money, string note, string staffCode)
        {
            try
            {
                OTHER_REVENUE item = CommonGlobalVariable.globalDataContext.OTHER_REVENUEs.FirstOrDefault(q => q.CODE == code);
                item.AMOUNT = money;
                item.NOTE = note;
                item.OPID = staffCode;
                item.UPD_DATE = DateTime.Now;
                CommonGlobalVariable.globalDataContext.SubmitChanges();
            }
            catch (Exception ex)
            {
                CommonLogging.fsWriteLog(CommonConstants.LOG_TYPE_ERROR,
                   "OtherRevenueCtrl.fsUpdateItem",
                   CommonUtils.fsParamListToString(new object[3] { code, money, note }),
                   ex.ToString());
                return ResultStatus.ERROR;
            }
            return ResultStatus.SUCCESS;
        }

        public ResultStatus fsDeleteItem(string code)
        {
            try
            {
                OTHER_REVENUE item = CommonGlobalVariable.globalDataContext.OTHER_REVENUEs.FirstOrDefault(q => q.CODE == code);
                item.DEL_FLG = CommonConstants.FLAG_ON;
                item.OPID = CommonUtils.fsGetOPID();
                item.UPD_DATE = DateTime.Now;
                CommonGlobalVariable.globalDataContext.SubmitChanges();
            }
            catch (Exception ex)
            {
                CommonLogging.fsWriteLog(CommonConstants.LOG_TYPE_ERROR,
                  "OtherRevenueCtrl.fsUpdateItem",
                  CommonUtils.fsParamListToString(new object[1] { code}),
                  ex.ToString());
                return ResultStatus.ERROR;
            }
            return ResultStatus.SUCCESS;
        }
    }
}
